﻿using DeviceCommons.DeviceMessages.Enums;

namespace DeviceCommons.DeviceMessages.Models
{
    public class DeviceMessageHeader : IDeviceMessageHeader
    {
        public DeviceMessageHeader()
        {
        }

        public byte[] Header { get; set; } = new byte[] { 0xC0, 0xBF };

        public byte Version { get; set; } = 0x01;

        public TimeStampFormatEnum TimeStampFormat { get; set; } = TimeStampFormatEnum.MS;

        public HeaderValueTypeEnum ValueType { get; set; } = HeaderValueTypeEnum.Standard;

        public Reserve1Enum Reserve1 { get; set; } = Reserve1Enum.Close;

        public Reserve2Enum Reserve2 { get; set; } = Reserve2Enum.Close;

        public CRCTypeEnum CRCType { get; set; } = CRCTypeEnum.CRC16;

        public byte Mark
        {
            get => (byte)((int)CRCType << 4 | (int)Reserve2 << 3 | (int)Reserve1 << 2 | (int)ValueType << 1 | (int)TimeStampFormat);
        }

        public int DataLength => 4;
    }
}
